﻿@model Wicresoft.SelfService.DAO.BreakDowmModel

@{
    Layout = null;
}

<script type="text/javascript">
$(function () {
    $(document).ready(function() {
       $("#lab2").hide();
    });
   $("#lvl1").change(function() 
   {
      var blvl1=$("#lvl1").find("option:selected").text(); 
      var v1=$("#lvl1").find("option:selected").val(); 
      if(v1!="0"){
          $("#Tier1").val(blvl1);
          if(blvl1=="应用系统")
          {
             $("#lab1").hide();
             $("#lab2").show();
             $("#type3").hide();
          }
          else if(blvl1=="外设")
          {
             $("#lab1").hide();
             $("#lab2").show();
             $("#type3").show();
          }
          else
          {
             $("#lab1").show();
             $("#lab2").hide();
             $("#type3").hide();
          }
      }
      else
      {
         $("#Tier1").val("");
         $("#lab1").show();
         $("#lab2").hide();
         $("#type3").show();
      }
    });


    var flag=false;

   $("#createBtn").click(function()
   {

        var lvl1=$("#Tier1").val();
        if(lvl1==null||lvl1==""){
            alert("故障一级分类不能为空");
            return false;
        }
        var lvl2=$("#Tier2").val();
        if(lvl2==null||lvl2==""){
            alert("故障二级分类不能为空");
            return false;
        }

        $.post("@Url.Action("SearchByTier2", "BDMaintain")", $("#breakForm").serialize(), 
            function(data){           
                if(data == "true"){
                   flag=true;
                }
                else{
                    alert("该故障二级分类已存在!");
                    flag=false;
                }
            })
        
        if(flag){
            $.post("@Url.Action("CreateBreak", "BDMaintain")", $("#breakForm").serialize(), 
            function(data){           
                if(data == "true"){
                    alert("创建成功");
                    $("#Tier1").val("");
                    $("#Tier2").val("");
                    $("#Tier3").val("");
                    location.reload();
                }
                else{
                    alert("创建失败");
                }
            })
        }
        
    });
});
</script>
<div class="right_title">添加故障分类</div>
<div class="right_box_top ui-icons">
</div>
<div class="right_box_bg">
    <div class="right_box">
         <div style="padding-bottom: 20px;">
            @using (Html.BeginForm("CreateBreak", "BDMaintain", FormMethod.Post, new { @id = "breakForm" }))
            {
                <table style="width:600px;">
                <tbody>
                    <tr>
                        <td colspan="4">
                            <b>步骤一：</b>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <p>【注】1.如果要在已有故障一级分类中创建，请先填写"<b>步骤一</b>"，在填写"<b>步骤二</b>";</p>
                            <p>【注】2.如果要全新创建一个故障分类(一)、(二)、(三)级，请直接填写"<b>步骤二</b>";</p>
                            <br />
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <th style="width: 40%;" align="right">
                            <label>选择添加已有<b>故障分类(一)</b>:</label>
                        </th>
                        <td align="left">
                            @{
                                List<SelectListItem> lvl1 = new List<SelectListItem>();
                                lvl1.Add(new SelectListItem { Text = "--------- 请选择 --------", Value = "0" });
                                foreach (var item in (IEnumerable<Wicresoft.SelfService.DAO.BreakConfig>)ViewData["lvl1"])
                                {
                                    lvl1.Add(new SelectListItem { Text = item.LvlName, Value = item.ID.ToString() });
                                }
                                @Html.DropDownList("lvl1", lvl1);
                            }
                        </td>
                        <th style="width: 40%;"></th>
                        <td></td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <hr />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <b>步骤二：</b>
                        </td>
                    </tr>
                    <tr>
                        <th style="width: 40%;" align="right">
                            <label>故障分类(一):</label>
                        </th>
                        <td align="left">
                            @Html.EditorFor(model => model.Tier1, new { id = "Tier1" })
                        </td>
                        <th style="width: 40%;"></th>
                        <td></td>
                    </tr>
                    <tr id="type2">
                        <th style="width: 40%;" align="right">
                            <label id="lab1">故障分类(二):</label>
                            <label id="lab2">故障分类(三):</label>
                        </th>
                        <td align="left">
                            @Html.EditorFor(model => model.Tier2, new { id = "Tier2" })
                        </td>
                        <th style="width: 40%;"></th>
                        <td></td>
                    </tr>
                    <tr id="type3">
                        <th style="width: 40%;" align="right">
                            <label>故障分类(三):</label>
                        </th>
                        <td align="left">
                            @Html.EditorFor(model => model.Tier3, new { id = "Tier3" })
                        </td>
                        <th style="width: 40%;"></th>
                        <td></td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <hr />
                        </td>
                    </tr>
                    <tr>
                        <th style="width: 40%;" align="right">
                        </th>
                        <td align="left">
                            <input class="Button1 ui-icons" type="button" id="createBtn" value="创建" style="margin-left: 45px; margin-top: 20px;" />
                        </td>
                        <th style="width: 40%;"></th>
                        <td></td>
                    </tr>
                    </tbody>
                </table>
                
            }
        </div>
    </div>
</div>
<div class="right_box_down ui-icons">
</div>

